package cn.javav.sso.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/auth")
public class AuthenticationController {
	
	
	@RequestMapping("/hasAuth.do")
	public void hasAuth(HttpServletRequest req ,HttpServletResponse resp){
		try {
			String json = "";
			String ticket = req.getParameter("ticket");
			if(ticket == null || "".equals(ticket)){
				json = "{hasAuth:no}";
			}else{
				json = "{hasAuht:yes}";
			}
			 resp.setContentType("text/html;charset=utf-8");
			 resp.getWriter().append(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	
	@RequestMapping("/isLogin.do")
	public void isLogin(HttpServletRequest req ,HttpServletResponse resp){
		try {
			String json = "";
			String token = (String) req.getSession().getAttribute("token");
			if(token == null || "".equals(token)){
				json = "{isLogin:no}";
			}else{
				json = "{isLogin:yes}";
			}
			 resp.setContentType("text/html;charset=utf-8");
			 resp.getWriter().append(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void appauth(String targetUrl){
		
	}
}
